package util;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.junior.activities.R;
import com.squareup.picasso.Picasso;


import java.util.List;

import basicas.Time;

/**
 * Created by Glauber on 02/11/2014.
 */
public class TimesAdapter extends BaseAdapter {

    private Context mContext;
    private List<Time> mTimes;

    public TimesAdapter(Context mContext, List<Time> mTimes) {
        this.mContext = mContext;
        this.mTimes = mTimes;
    }

    @Override
    public int getCount() {
        return mTimes.size();
    }

    @Override
    public Object getItem(int position) {
        return mTimes.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Time time = mTimes.get(position);

        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate( R.layout.time_item, null);
        }
        ImageView imgEscudo = (ImageView)convertView.findViewById(R.id.imgEscudo);
        TextView txtTime = (TextView)convertView.findViewById(R.id.txtTime);

        Picasso.with(mContext).load(time.escudo).into(imgEscudo);
        txtTime.setText(time.nome);

        return convertView;
    }
}
